package com.gopay.common.rcs.service.translimit.impl;

import com.gopay.common.constants.proccode.ProcCodeEnum;
import com.gopay.common.constants.riskcontrol.RiskControlConstants;
import com.gopay.common.constants.txncd.IntTxnCd;
import com.gopay.common.domain.rcs.req.RcsTransLimitRequest;
import com.gopay.common.domain.rcs.res.RcsTransLimitResponse;
import com.gopay.common.rcs.service.translimit.RcsTransLimitService;
import com.gopay.common.riskcontrol.dao.RcListingQueryDAO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 交易额度校验
 * @RcsTransLimitProxyServiceImpl.java
 * @author liujy
 * @2013-9-17 下午4:52:13  www.gopay.com.cn Inc.All rights reserved.
 */
@Service("rcsTransLimitService")
public class RcsTransLimitProxyServiceImpl implements RcsTransLimitService {

   /* @Resource(name="rcsTransLimitServices")
    private Map<String, RcsTransLimitService> rcsTransLimitServices;
    
    private final String DEFAULT_RCS_TRANS_LIMIT_SERVICE = "defaultRcsTransLimitService";*/
    
    @Resource(name="rcsTransLimitFor00700Service")
    private RcsTransLimitService rcsTransLimitFor00700Service;
    @Resource(name="rcsTransLimitBaseService")
    private RcsTransLimitService rcsTransLimitBaseService;

    //add by liuyu, 20170706, 风控白名单
    @Resource(name = "rcListingQueryDAO")
    private RcListingQueryDAO rcListingQueryDAO;
    
    @Override
    public RcsTransLimitResponse rcsTransLimitProcess(RcsTransLimitRequest request) {
        
        if (null == request) {
            RcsTransLimitResponse response = new RcsTransLimitResponse();
            response.setProcCode(ProcCodeEnum.PROC_CODE_200E1001.getCode());
            return response;
        }
        //add by liuyu, 20170707, 风控白名单跳过额度校验-----start----->
        if(rcListingQueryDAO.queryRcListing(request.getCustId(), RiskControlConstants.RCLISTING_RISK_WHITE,
                RiskControlConstants.RCLISTING_ACTIVE) != null){
            RcsTransLimitResponse response = new RcsTransLimitResponse();
            response.setProcCode(ProcCodeEnum.PROC_CODE_200S1000.getCode());
            response.setProcCodeMsg("客户custId:" + request.getCustId() + "在风控白名单中，跳过额度校验");
            return response;
        }
        //add by liuyu, 20170707, 风控白名单跳过额度校验------end------>
        if(IntTxnCd._00700.equals(request.getIntTxnCd())){
            return rcsTransLimitFor00700Service.rcsTransLimitProcess(request);
        }
        
        return rcsTransLimitBaseService.rcsTransLimitProcess(request);
    }
}